using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Assertions;
using System;

public class NewBehaviourScript1 : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        //调用ts类静态函数
        OpenHarmonyJSClass openHarmonyJSClass = new OpenHarmonyJSClass("StaticClassTest");
        openHarmonyJSClass.CallStatic("voidFunc");
        Debug.Log("StaticClassTest c######:expected 3 ,result :"+openHarmonyJSClass.CallStatic<int>("intFunc",1,2));
        Debug.Log("StaticClassTest c######: true ,result :"+openHarmonyJSClass.CallStatic<bool>("boolFunc"));
        Debug.Log("StaticClassTest c######: 255 ,result :"+openHarmonyJSClass.CallStatic<Byte>("byteFunc"));
        Debug.Log("StaticClassTest c######: -128 ,result :"+openHarmonyJSClass.CallStatic<SByte>("sbyteFunc"));
        Debug.Log("StaticClassTest c######: 32767 ,result :"+openHarmonyJSClass.CallStatic<Int16>("int16Func"));
        Debug.Log("StaticClassTest c######:expected Int64.MaxValue ,result :"+openHarmonyJSClass.CallStatic<Int64>("int64Func"));
        Debug.Log("StaticClassTest c######:expected Z ,result :"+openHarmonyJSClass.CallStatic<Char>("charFunc"));
        

        //回调函数测试
        static void Log(string log){
            Debug.Log(log);
        }
        static void call_back_func(params OpenHarmonyJSObject[] args){
            var intObj = args[0];
            var strObj = args[1];
            int intVal = intObj.As<int>();
            string strVal = strObj.As<string>();
            Log("c###### call_back_func intVal:"+intVal +",strVal:"+strVal);
        }
        var openHarmonyJsCallback = new OpenHarmonyJSCallback(call_back_func);
        openHarmonyJSClass.CallStatic("callbackFunc",openHarmonyJsCallback);

        // var sensor = new OpenHarmonyJSObject("sensor");
        // var sensorOnCallback = new OpenHarmonyJSCallback(SensorOnCallback);
        // sensor.Call("once",256,sensorOnCallback);
        // Regex reg = new Regex(@"Sensor object in callback.*？");
        //LogAssert.Expect(LogType.Log,reg);


        //调用ts类对象函数
        OpenHarmonyJSObject openHarmonyJSObject = new OpenHarmonyJSObject("ClassObjectTest");
        Debug.Log("ClassObjectTest c######:expected 3 ,result :"+openHarmonyJSObject.Call<int>("intFunc",1,2));
        Debug.Log("ClassObjectTest c######:expected 255 ,result :"+openHarmonyJSObject.Call<Byte>("byteFunc"));
        Debug.Log("ClassObjectTest c######:expected HelloworldJS ,result :"+openHarmonyJSObject.Call<String>("stringFunc","1","2"));
        string[] stringArray = new[]{"AA","BB","CC"};
        System.Array resultArray = openHarmonyJSObject.Call<Array>("stringArrayFunc", stringArray);
        // 显式转换为 string[]
        string[] stringArray_added = resultArray as string[];
        if (stringArray_added != null)
        {
            // 打印 stringArray_added 的内容
            foreach (var item in stringArray_added)
            {
                Debug.Log("stringArray_added item: " + item);
            }
        }
    }

}
